import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

// 解决重复点击报错的问题
const originalPush = VueRouter.prototype.push;
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}

const routes = [
  {
    path: '/',
    name: 'Discover',
    redirect: '/discover'
  },
  {
    path: '/discover',
    component: () => import('@/views/discover/Discover'),
    children: [
      {
        path: '/discover',
        redirect: '/discover/recommend',
      },
      {
        path: '/discover/recommend',
        component: () => import('@/views/discover/childrouter/recommend/Recommend')
      },
      {
        path: '/discover/toplist',
        component: () => import('@/views/discover/childrouter/toplist/TopList')
      },
      {
        path: '/discover/playlist',
        component: () => import('@/views/discover/childrouter/playlist/Playlist'),
      },
      {
        path: '/discover/djradio',
        component: () => import('@/views/discover/childrouter/djradio/Djradio')
      },
      {
        path: '/discover/artist',
        component: () => import('@/views/discover/childrouter/artist/Artist')
      },
      {
        path: '/discover/album',
        component: () => import('@/views/discover/childrouter/album/Album')
      },
      {
        path: '/discover/playlist/detail',
        component: () => import('@/views/discover/childrouter/playlistdetail/PlaylistDetail')
      },
      {
        path: '/discover/song/detail',
        component: () => import('@/views/discover/childrouter/songdetail/SongDetail')
      }      
    ]
  },
  {
    path: '/my',
    component: () => import('@/views/my/My')
  },
  {
    path: '/friend',
    component: () => import('@/views/friend/Friend')
  },
  {
    path: '/download',
    component: () => import('@/views/download/Download')
  },
  {
    path: '/store',
    component: () => import('@/views/store/Store')
  },
  {
    path: '/nmusician',
    component: () => import('@/views/nmusician/Nmusician')
  }

]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes,
  // 刷新或路由跳转时回顶部
  scrollBehavior(to, from,savedPosition) {
    return {
      x: 0,
      y: 0
    }
  }
})

export default router
